package com.jiwei.system.serviceImpl;

import com.jiwei.system.pojo.ResultPoJo;
import com.jiwei.system.service.LoginService;
import com.jiwei.system.vo.Login;
import com.jiwei.system.utils.JWTUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * @title: SMSLoginService
 * @Author 赖志宇
 * @Description 短信登陆
 * @Date: 2020/8/16
 * @Version 1.0
 */

@Service("SMSLogin")
public class SMSLoginService implements LoginService<Login> {

    @Resource
    HttpSession httpSession;

    public SMSLoginService() {
        userLoginMethodMap.put("SMS", this);
    }


    @Override
    public ResultPoJo verifyLogin(Login login) {
        return login.equals(httpSession.getAttribute("login")) ?
                new ResultPoJo("200") : new ResultPoJo("400");
    }

    @Override
    public ResultPoJo beforeLogin(Login login) {
        return null;
    }

    @Override
    public ResultPoJo loginFail(Login login) {
        return  new ResultPoJo("400", "登陆失败", null);
    }


    @Override
    public ResultPoJo loginSuccess(Login login) {
        return new ResultPoJo("200", "登陆成功", JWTUtil.createLoginToken(login.getAccount()));
    }
}
